using System;
using System.Collections.Generic;

namespace Verse;

public static class MapComponentUtility
{
	public static void MapComponentUpdate(Map map)
	{
		List<MapComponent> components = map.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].MapComponentUpdate();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void MapComponentTick(Map map)
	{
		List<MapComponent> components = map.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].MapComponentTick();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void MapComponentOnGUI(Map map)
	{
		List<MapComponent> components = map.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].MapComponentOnGUI();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void FinalizeInit(Map map)
	{
		List<MapComponent> components = map.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].FinalizeInit();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void MapGenerated(Map map)
	{
		List<MapComponent> components = map.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].MapGenerated();
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
			}
		}
	}

	public static void MapRemoved(Map map)
	{
		List<MapComponent> components = map.components;
		for (int i = 0; i < components.Count; i++)
		{
			try
			{
				components[i].MapRemoved();
			}
			catch (Exception ex)
			{
				Log.Error("Could not notify map component: " + ex);
			}
		}
	}
}
